- frmRegisteredUsersDetails.cs
- project /
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 namespace WarehouseManagementSystem
11 {
12 public partial class frmRegisteredUsersDetails : Form
13 {
14 ConnectionString cs = new ConnectionString();
15 public frmRegisteredUsersDetails()
16 {
17 InitializeComponent();
18 }
19
20 private SqlConnection Connection
21 {
22 get
23 {
24 SqlConnection ConnectionToFetch = new SqlConnection(cs.DBConn);
25 ConnectionToFetch.Open();
26 return ConnectionToFetch;
27 }
28 }
29 public DataView GetData()
30 {
31 dynamic SelectQry = "SELECT RTRIM(Username) as [User Name],RTRIM(Password) as [Password],RTRIM(Name) as [Name],RTRIM(ContactNo) as [Contact No.],RTRIM(Email) as [Email ID],RTRIM(joiningdate) as [Date Of Joining] FROM registration";
32 DataSet SampleSource = new DataSet();
33 DataView TableView = null;
34 try
35 {
36 SqlCommand SampleCommand = new SqlCommand();
37 dynamic SampleDataAdapter = new SqlDataAdapter();
38 SampleCommand.CommandText = SelectQry;
39 SampleCommand.Connection = Connection;
40 SampleDataAdapter.SelectCommand = SampleCommand;
41 SampleDataAdapter.Fill(SampleSource);
42 TableView = SampleSource.Tables[0].DefaultView;
43 }
44 catch (Exception ex)
45 {
46 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
47 }
48 return TableView;
49 }
50 private void frmRegisteredUsersDetails_Load(object sender, EventArgs e)
51 {
52 dataGridView1.DataSource = GetData();
53 }
54 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
55 {
56 string strRowNumber = (e.RowIndex + 1).ToString();
57 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
58 if (dataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
59 {
60 dataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
61 }
62 Brush b = SystemBrushes.ControlText;
63 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
64 }
65
66
67 }
68 }